package ae.pcfc.cldos.online.common.strategy.mail.sender.provider;

import java.util.Date;
import java.util.Map;

import ae.pcfc.cldos.online.common.clddb.domain.AppMetaData;
import ae.pcfc.cldos.online.common.clddb.domain.MessageInbox;
import ae.pcfc.cldos.online.common.strategy.mail.sender.BaseEmailBuilder;
import ae.pcfc.cldos.online.common.strategy.mail.sender.IEmailSender;
import ae.pcfc.cldos.online.common.strategy.mail.sender.MailToUserSenderThread;
import ae.pcfc.cldos.online.gs.service.client.vo.NotificationVO;

/**
 * 
 * @author arosa
 *
 */
public class MainUserLaunchMailStrategy extends BaseEmailBuilder implements IEmailSender {

	public void sendEmail(AppMetaData appMetaData, NotificationVO notificationVO) {
		notificationVO.setSubject(subject);
		notificationVO.setSubjectAr(subjectAr);
		Map<Object, Object> params =  notificationVO.getParameters();
			params.put("refNo", appMetaData.getClientRefNo());
			try{
				notificationVO.setMessage(
						ftlProcessorManager.processFtlTemplate(templateName, params));
				notificationVO.setMessageAr(
						ftlProcessorManager.processFtlTemplate(templateName+"_ar", params));
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			MessageInbox messageInboxNotification = new MessageInbox();
			messageInboxNotification.setMiMsgType(MessageInbox.MESSAGE_TYPE_NOTIFICATION);
			messageInboxNotification.setMiSentOn(new Date());
			messageInboxNotification.setMiActionFlag(MessageInbox.MESSAGE_ACTION_FLAG_NOT_DONE);
			messageInboxNotification.setMiDtls(notificationVO.getMessage());
			messageInboxNotification.setMiSubject(notificationVO.getSubject());
			messageInboxNotification.setAppId(appMetaData.getApplicationId());
			messageInboxDOM.add(messageInboxNotification);
			
			notificationVO.setEmailsList(userDomainObjectManager.getMainUsersEmailsListByCliendId(appMetaData.getClientId()));
			MailToUserSenderThread mailToUserSenderThread = new MailToUserSenderThread(govtSysGS, notificationVO,fileStorageManager);
			mailToUserSenderThread.start();
		
	}

}
